from tools.listNode import listToNode


def isPalindrome(head):
    if not head:
        return True
    arr = []
    while head:
        arr.append(head.val)
        head = head.next
    i, j = 0, len(arr) - 1
    while i < j:
        if arr[i] != arr[j]:
            return False
        i += 1
        j -= 1
    return True


print(isPalindrome(listToNode([1, 2, 3])))
print(isPalindrome(listToNode([1, 2, 2, 1])))
print(isPalindrome(listToNode([1, 2, 1])))
